import { HashRouter, Route, Redirect, Switch } from 'react-router-dom'
import Center from '../views/Center'
import Films from '../views/Films'
import Cinemas from '../views/Cinemas'
import Detail from '../views/Detail'
import Login from '../views/Login'

import React, { Component } from 'react'
import NotFound from '../views/NotFound'

function isAuth() {
    return localStorage.getItem('token')
}

export default class IndexRouter extends Component {
    render() {
        return (
            <div>
                <HashRouter>
                    {this.props.children}
                    <Switch>
                        <Route path="/films" component={Films} />
                        <Route path="/cinemas" component={Cinemas} />
                        {/* <Route path="/center" component={Center} /> */}
                        <Route path="/center" render={() => {
                            return isAuth() ? <Center /> : <Redirect to="/login" />
                        }} />
                        {/* <Route path="/detail/" component={Detail} /> */}
                        <Route path="/detail/:filmId" component={Detail} />

                        <Route path="/login" component={Login} />

                        <Redirect from="/" to="/films" exact />
                        <Route path="*" component={NotFound} />
                    </Switch>
                </HashRouter>
            </div>
        )
    }
}
